Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

879
Views
"No set method providing array access" -- why does this happen in Kotlin?

Here's the code.

val stack = Array(inputString.length + 1) { "" }
var current = 0
for ((i, char) in inputString.withIndex()) {
    if (char == '(') {
        current += 1
        continue
    } else if (char == ')') {
        val enclosedString = stack[current]
        stack[current - 1] = stack[current - 1] + enclosedString.reversed()
        current -= 1
        continue
    } else {
        stack[current] +=  char //here's the compile time error 
    }
}

I'm getting an error saying "No set method providing array access". I don't understand this.

If I change it to:

stack[current] = stack[current] + char

things work fine.

Why is this happening?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The cause of the error is the incorrect assignment of a Char variable to an Array<String>, you need to convert the Char to String before, and that's what is happening in the statement

stack[current] = stack[current] + char

The + function returns a new String concatenating with the string representation of the right side (i.e. it automatically call toString in the right operand). In other words, it is converting the Char variable char to String before the concatenation.

You can also convert it yourself.

stack[current] += char.toString()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!